package com.ruoyi.order;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.TOrderShort;
import com.ruoyi.order.service.ITOrderShortService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 短token订单Controller
 * 
 * @author ruoyi
 * @date 2023-02-09
 */
@RestController
@RequestMapping("/order/short")
public class TOrderShortController extends BaseController
{
    @Autowired
    private ITOrderShortService tOrderShortService;

    /**
     * 查询短token订单列表
     */
    @PreAuthorize("@ss.hasPermi('order:short:list')")
    @GetMapping("/list")
    public TableDataInfo list(TOrderShort tOrderShort)
    {
        startPage();
        List<TOrderShort> list = tOrderShortService.selectTOrderShortList(tOrderShort);
        return getDataTable(list);
    }

    /**
     * 导出短token订单列表
     */
    @PreAuthorize("@ss.hasPermi('order:short:export')")
    @Log(title = "短token订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TOrderShort tOrderShort)
    {
        List<TOrderShort> list = tOrderShortService.selectTOrderShortList(tOrderShort);
        ExcelUtil<TOrderShort> util = new ExcelUtil<TOrderShort>(TOrderShort.class);
        util.exportExcel(response, list, "短token订单数据");
    }

    /**
     * 获取短token订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:short:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tOrderShortService.selectTOrderShortById(id));
    }

    /**
     * 新增短token订单
     */
    @PreAuthorize("@ss.hasPermi('order:short:add')")
    @Log(title = "短token订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TOrderShort tOrderShort)
    {
        return toAjax(tOrderShortService.insertTOrderShort(tOrderShort));
    }

    /**
     * 修改短token订单
     */
    @PreAuthorize("@ss.hasPermi('order:short:edit')")
    @Log(title = "短token订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TOrderShort tOrderShort)
    {
        return toAjax(tOrderShortService.updateTOrderShort(tOrderShort));
    }

    /**
     * 删除短token订单
     */
    @PreAuthorize("@ss.hasPermi('order:short:remove')")
    @Log(title = "短token订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tOrderShortService.deleteTOrderShortByIds(ids));
    }
}
